package main

import (
	"bufio"
	"fmt"
	"gitee.com/xiakai001/goutl/cmdutl"
	"gitee.com/xiakai001/goutl/errutl"
	"os"
	"strings"
	"time"
)

func main() {

	defer func() {
		for {
			_, _ = fmt.Scanln()
		}
	}()

	err := handle()
	if err != nil {
		println(err.Error())
	}

}

func handle() error {

	fmt.Print("请输入命令(#结尾)：\n")

	reader := bufio.NewReader(os.Stdin)

	inputs := make([]string, 0, 10)
	for {
		// 读取整行输入
		input, err := reader.ReadString('\n')
		if err != nil {
			return errutl.Wrap(err)
		}
		input = strings.TrimSpace(input)
		if input == "#" {
			break
		}
		if len(input) != 0 {
			inputs = append(inputs, input)
		}
	}

	println("开始任务")
	time.Sleep(time.Second * 1)

	for _, input := range inputs {
		err := cmdutl.Exec(input)
		if err != nil {
			return errutl.Wrap(err)
		}
	}

	println()
	println()
	println("success!!")
	println()
	println()

	return nil
}
